package io.decorated.byte_;

import java.io.*;


public class BufferedCopy {

    public static void main(String[] args) {
        String srcFilePath = "";
        String desFilePath = "";

        /**
         * 字节流操作二进制文件
         * 字节流可以操作文本文件吗？当然可以，因为字节是最小的数据单元了
         */
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
        bis = new BufferedInputStream(new FileInputStream(srcFilePath));
        bos = new BufferedOutputStream(new FileOutputStream(desFilePath));

        //循环读取文件到buf 并写入目标文件
        byte[] buff = new byte[1024];
        int readLen = 0;
            while ((readLen = bis.read(buff)) != -1) {
                bos.write(buff, 0, readLen);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //关闭外层流即可
            try {
                if (bis != null) {
                   bis.close();
                }
                if (bos != null) {
                    bos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
            }
        }

    }


}
